package com.sshtools.view.model;

import java.io.File;
import java.util.List;

import com.thoughtworks.xstream.XStream;

import tsif.component.log.Log;
import tsif.utils.FileUtils;

/**
 * 对应配置里的Server,每个服一个配置.
 * 
 */
public class ServerModel {
	protected String name; // 服务器名称
	protected String domain; // 域名
	protected String host; // 远程主机地址
	protected int port; // 端口号
	protected String username; // 登陆用户名
	protected String password; // 登陆密码
	protected String keyFile; // 密钥文件路径
	
	protected String uploadPath; // 游戏文件路径(网络路径)
	protected String localPath; // 上传文件路径(本地路径)
	protected String remotePath; //远程目录(对指令有效)
	protected String restartCommand; // 重启指令
	protected String startCommand; // 启动指令
	protected String stopCommand; // 关闭指令
	protected int timeout; // 连接超时

	public String getName() {
		return name;
	}

	public String getDomain() {
		return domain;
	}

	public String getHost() {
		return host;
	}

	public int getPort() {
		return port;
	}

	public String getUsername() {
		return username;
	}

	public String getPassword() {
		return password;
	}

	public String getKeyFile() {
		return keyFile;
	}

	public String getUploadPath() {
		return uploadPath;
	}

	public String getLocalPath() {
		return localPath;
	}

	public String getRestartCommand() {
		return restartCommand;
	}

	public String getStartCommand() {
		return startCommand;
	}

	public String getStopCommand() {
		return stopCommand;
	}

	public int getTimeout() {
		return timeout;
	}

	/** 加载文件 **/
	@SuppressWarnings("unchecked")
	public static List<ServerModel> load(String path) {
		File file = new File(path);
		if (!file.exists()) {
			Log.error("找不到文件!  " + FileUtils.getAbsolutePath(path));
			return null;
		}

		XStream xs = new XStream();
		xs.alias("servers", List.class);
		xs.alias("server", ServerModel.class);
		return (List<ServerModel>) xs.fromXML(file);
	}

	@Override
	public String toString() {
		return "" + name + " [" + username + "@" + host + ":" + port + "]";
	}

	public String getRemotePath() {
		return remotePath;
	}

	public void setRemotePath(String remotePath) {
		this.remotePath = remotePath;
	}

}
